package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service()
@Slf4j
public class RecommendUserService {
    @Reference(version = "1.0.0",check = false)
    private RecommendUserApi recommendUserApi;
    public TodayBest queryTodayBest(Long id){

        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        try {
            log.info(recommendUser.toString());
            if(recommendUser==null)
                return null;
        } catch (Exception e) {
            log.error("推荐今日佳人出错，推荐用户为空----id="+id+e);
        }
        TodayBest todayBest=new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        //yuanfzhi
        Double floor = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(floor.longValue());
        return todayBest;

    }

    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {

        PageInfo<RecommendUser> PageInfo = recommendUserApi.queryPageInfo(id, page, pagesize);
        if(PageInfo==null)
        {
            return null;
        }
        return PageInfo;

            }
    /**
     * 查询推荐好友的缘分值
     *
     * @param userId
     * @param toUserId
     * @return
     */
    public Double queryScore(Long userId, Long toUserId){
        Double score = this.recommendUserApi.queryScore(userId, toUserId);
        if(ObjectUtil.isNotEmpty(score)){
            return score;
        }
        //默认值
        return 98d;
    }

    public List<RecommendUser> queryCardList(Long id, int count) {
      return   recommendUserApi.queryCardList(id,count);
    }
}
